package com.shaw.workrecord.entity;

import lombok.Data;

/**
 * @author jh.jiang
 * date 2022-04-17
 * description
 */
@Data
public class ResponseBean<T> {

    private Integer code;

    private String message;

    private T data;

    public ResponseBean(T data, Integer code, String message) {
        this.data = data;
        this.code = code;
        this.message = message;
    }

    public static <T> ResponseBean<T> success(T data, String message) {
        ResponseBean<T> rest = new ResponseBean<T>( data, 100, message);
        return rest;
    }

    public static <T> ResponseBean<T> success(T data) {
        return success(data, "操作成功");
    }

    public static <T> ResponseBean<T> failure() {
        return new ResponseBean<T>(null, 200, "操作失败");
    }

    public static <T> ResponseBean<T> failure(String message) {
        return new ResponseBean<T>(null, 200, message);
    }

    public static <T> ResponseBean<T> failure(int errorCode) {
        return new ResponseBean<T>(null, errorCode, "操作失败");
    }

    public static <T> ResponseBean<T> failure(int errorCode, String message) {
        return new ResponseBean<T>(null, errorCode, message);
    }
}
